<?php

class Employer_ManageController extends Kieumau_Controller_Employer
{
    public function init()
    {
		parent::init();
    	$this->createTemplate(TEMPLATE_PATH, 'template', 'default/template.ini' );
    }
	
	public function preDispatch() {
		
		$ntd = new Zend_Session_Namespace ( 'employerntd' );			
		if (empty($ntd->employerntd)) {//Nếu chưa đăng nhập thì session sẽ rỗng
			$actionAllow = array();
			if (! in_array($this->_request->getActionName (), $actionAllow)) {
				$this->_redirect ( '/employer/index' );//Đưa sang trang index
			}
		}
	}

    public function indexAction()
    {
		$this->view->mainMenuFocus	  	= "manageRecruiment";
		$this->view->submainMenuFocus 	= "myjob";
		$this->view->submainMenuFocus2 	= "online";
		
    	//Lấy danh sách job của nhà tuyển dụng này
		$ntd = new Zend_Session_Namespace ( 'employerntd' );
		
    	$commonTable = new Kieumau_Db_Common();
		$jobList = $commonTable->getAll('job','status = ? AND employer_id = ?',array(2,$ntd->employerntd['id']));
		$this->view->jobList = $jobList;
    }
	
	public function draftAction(){
		$this->view->mainMenuFocus	  	= "manageRecruiment";
		$this->view->submainMenuFocus 	= "myjob";
		$this->view->submainMenuFocus2 	= "draft";
		
		$ntd = new Zend_Session_Namespace ( 'employerntd' );
		
    	$commonTable = new Kieumau_Db_Common();
		$jobList = $commonTable->getAll('job','status = ? AND employer_id = ?',array(1,$ntd->employerntd['id']));
		$this->view->jobList = $jobList;
	}
	
	public function expiredAction(){
		$this->view->mainMenuFocus	  	= "manageRecruiment";
		$this->view->submainMenuFocus 	= "myjob";
		$this->view->submainMenuFocus2 	= "expired";
		
		$ntd = new Zend_Session_Namespace ( 'employerntd' );
		
    	$commonTable = new Kieumau_Db_Common();
		$jobList = $commonTable->getAll('job','DATE_FORMAT(SYSDATE(),"%Y-%m-%d %H:%i:%s") > expire_date AND employer_id = ?',array($ntd->employerntd['id']));
		
		$this->view->jobList = $jobList;
	}
	
	public function expiringsoonAction(){
		$this->view->mainMenuFocus	  	= "manageRecruiment";
		$this->view->submainMenuFocus 	= "myjob";
		$this->view->submainMenuFocus2 	= "expiring";
		
		$ntd = new Zend_Session_Namespace ( 'employerntd' );
		
    	$commonTable = new Kieumau_Db_Common();
		
		$jobList = $commonTable->getAll('job','DATE_ADD(DATE_FORMAT(SYSDATE(),"%Y-%m-%d %H:%i:%s"),INTERVAL 7 DAY) > expire_date AND employer_id = ?',array($ntd->employerntd['id']));
		$jobList = $commonTable->getAll('job','expire_date BETWEEN
DATE_FORMAT(SYSDATE(),"%Y-%m-%d %H:%i:%s") 
AND 
DATE_ADD(DATE_FORMAT(SYSDATE(),"%Y-%m-%d %H:%i:%s"),INTERVAL 7 DAY) 
AND employer_id = ?',array($ntd->employerntd['id']));
		$this->view->jobList = $jobList;
	}
	
}